<script src="<?php echo $base_url?>js/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
function memreports(report_id) {
	window.location='index.php?report_id='+report_id;
}

function funDelMem(report_id) {
	var delPro=confirm("Are you sure want to delete this report?");
	if(delPro==true) {
		var frm = document.getElementById('form1');
		document.getElementById("delMember").value=report_id;
		frm.submit();
	}	
}

</script>
<?php
require_once "../includes/pagination.php";

if(!empty($_POST['delMember']))
{
	$memberId=$_POST['delMember'];
	$sqlDelMem="Delete from tbl_report where report_id=$memberId";
	$rstDelMem=mysql_query($sqlDelMem);	
}

$cond = '';
$sort = '';
$ut = $u = $fn = $ln = $dg = 'asc';
if(isset($_GET['sort']))
{
 if($_GET['sort']=='user_name')
 {
  if($_GET['s_type']=='asc')
  {	$cond=' ORDER BY name ASC';	$sort = '&sort=user_name&s_type=asc';	$ut='desc';	}
  else
  {	$cond=' ORDER BY name DESC';	$sort = '&sort=user_name&s_type=desc';	}
 }
 
}


?>
<form name="form1" id="form1" method="post" action="">
 <input type="hidden" name="delMember" id="delMember">
			  
<table width="100%"  border="1" cellspacing="0" class="container">
  <tr>
    <td width="469" height="25" class="tdHeader">Reports  List</td>
  </tr>
  <tr>
    <td height="577">
	<table width="100%">
			    <tbody>
				   <tr>
					  <td>
						 <form name="frmSearchPro" action="" method="post">
							<table width="100%" border="0">
							       <tr>
								      <td width="20%">Name</td>
								      <td width="30%">
									      <input type="text" name="user_name" id="user_name" style="width: 150px;" value="<?php echo $_POST['user_name']?>" />
								      </td>
								      <td width="20%">Email</td>
								      <td width="30%"><input type="text" name="email" id="email" style="width: 150px;" value="<?php echo $_POST['email']?>" /></td>
							       </tr>
							      
				  
							       <tr>
								       <td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search Reports" /></td>
							       </tr>
							</table>
						 </form>
					  </td>
				   </tr>
				   <tr>
					  <td>
						 <b>Sort  By :</b>
						 <a href="<?php echo $base_url;?>admin/index.php?reports&sort=user_name&s_type=<?php echo $ut;?>">Name</a> &nbsp;&nbsp;&nbsp;
						 
					  </td>
				   </tr>
			    </tbody>
		     </table><br>
	<table width="100%"  border="0" cellspacing="0">      
      <tr class="InnerHeader">       
        <td width="16%" class="line">Subject </td>
	<td width="13%" class="line">Name </td>
	<td width="14%" class="line">Email </td>
        <td width="8%" class="line">&nbsp;</td>
        <td width="7%" class="line">&nbsp;</td> 
		<td width="10%" class="line">&nbsp;</td>         
      </tr>
      <?php 				 
	
	$itemPerPage=15;
	$search='';
	if(isset($_POST['btnSearchPro'])) {
		
		$email 	= $_POST['email'];
		$first_name 	= $_POST['user_name'];
		
		
		if($first_name!='')
		$search.=" WHERE name='".$first_name."'";
		
		if($email!='' && $search!="")
		$search.=" AND email='".$email."'";
		else if($email!='' && $search=="")
		$search.=" WHERE email='".$email."'";
		
	}
	
	$sql_shocat="SELECT * FROM  tbl_report $search $cond";				 
	$rst_shocat=mysql_query(getPagingQuery($sql_shocat,$itemPerPage));
	$numRows = mysql_num_rows($rst_shocat);
	if($numRows>0) {				
		while($row_shocat = mysql_fetch_array($rst_shocat)) {				 
		$report_id=$row_shocat['report_id'];
		$email=$row_shocat['email'];
		$subject=$row_shocat['subject'];
		$name=$row_shocat['name'];
					       
		
		echo "<tr>";
		echo "<td class='line'>$subject</td>";
		echo "<td class='line'>$name</td>";
		echo "<td class='line'>$email</td>";
		
		echo "<td height='20' class='line'>&nbsp;</td> ";
		echo "<td height='20' class='line'><input type='button' name='view' value='View' class='button'  onclick='memreports($report_id)'></td> ";
		echo "<td height='20' class='line'><input type='button' name='delete' value='Delete' class='button'  onclick='funDelMem($report_id)';></td> ";
		echo "</tr>";				
		}
	} else {
	       echo "<tr>
			       <td colspan='8' class='line'>No Reports found.</td>
			 </tr>";
	}				 
		?>      
       </table>
	<div align="center">
		<?php		   
		   $link="members";
		   echo $disp=getPagingLink($sql_shocat,$itemPerPage,$link,$sort);							   
		?>    
	</div>
	</td>
 </tr>
</table>